package demo2;

class Person {

}
public class Test {

    public static void main(String[] args) {
        String str1 = new String("abcd");;
        System.out.println(str1);

        final int[] array = {1,2,3,4};
        array[0] = 9;
        //array = new int[10];

    }

    public static void main17(String[] args) {
        String str1 = "abcd";
        //String str2 = new String("abcd");
        String str3 = "abcd";
        System.out.println(str1 == str3);
    }

    public static void main16(String[] args) {
        String str = "  hello   abcd      ";
        System.out.println(str);
        String ret = str.trim();
        System.out.println(ret);
    }

    public static void main15(String[] args) {
        String str = "abcdefgh";
        //返回 从2位置开始 截取的所有字符
        String s = str.substring(2);
        System.out.println(s);

        String s2 = str.substring(2,6);//[) 返回新的字符串对象
        System.out.println(s2);
    }

    public static void main14(String[] args) {
        String str = "name=zhangsan&age=18" ;
        String[] strs = str.split("&");
        for (int i = 0; i < strs.length; i++) {
            //System.out.println(strs[i]);
            String[] strings = strs[i].split("=");
            for (String s : strings) {
                System.out.println(s);
            }
        }
    }

    public static void main13(String[] args) {
        String str1 = "192&168=1";
        String[] strs = str1.split("&|=");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }

    public static void main12(String[] args) {
        String str1 = "192\\168\\0\\1";
        String[] strs = str1.split("\\\\");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }

    public static void main11(String[] args) {
        String str1 = "192.168.0.1";
        String[] strs = str1.split("\\.");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }

    public static void main10(String[] args) {
        String str1 = "hello little bitter ";
        String[] strs = str1.split(" ",2);
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }

    public static void main9(String[] args) {
        String str1 = "ababcabcdabcde";
        String ret1 = str1.replace('a','p');
        System.out.println(ret1);
        //由于字符串是不可变对象, 替换不修改当前字符串, 而是产生一个新的字符串
        String ret2 = str1.replace("ab","ooo");
        System.out.println(ret2);

        String ret3 = str1.replaceAll("ab","666");
        System.out.println(ret3);

        String ret4 = str1.replaceFirst("ab","999");
        System.out.println(ret4);

    }
    public static void main8(String[] args) {
        String str1 = "abcdef";
        char[] array = str1.toCharArray();

        String s = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s);
    }


    public static void main7(String[] args) {
        String str1 = "abcd";
        String str2 = "ABcd";
        System.out.println(str1.toUpperCase());
        System.out.println(str2.toLowerCase());

    }


    public static void main6(String[] args) {
        String str2 = String.valueOf(123);
        System.out.println(str2);
        String str3 = String.valueOf(new Person());
        System.out.println(str3);
        System.out.println("========");

        String str1 = "123";
        //基本类型对应 的类类型   所以  基本类型 也提供了面向对象的思想
        int data = Integer.parseInt(str1);
        double data2 = Double.parseDouble(str1);
        System.out.println(data2);

    }
    public static void main5(String[] args) {
        String str1 = "ababcabcdabcde";

        System.out.println(str1.lastIndexOf("abc",8));


        /*System.out.println(str1.indexOf('c',6));
        //在主串当中  查找子串  KMP算法
        System.out.println(str1.indexOf("abcd"));
        */


        /*char ch = str1.charAt(1);
        charAt方法：返回index位置上字符，如果index为负数或者越界，抛出
        IndexOutOfBoundsException异常

        System.out.println(ch);*/

        /*for (int i = 0; i < str1.length(); i++) {
            System.out.println(str1.charAt(i));
        }*/

    }


    public static void main4(String[] args) {
        String str1 = new String("Hello");
        String str2 = new String("hello");
        //str1 和 str2进行比较

        //compareTo 与 equals不同的是，equals返回的是boolean类型，而compareTo返回的是int类型。具体比较方式：
        //1. 先按照字典次序大小比较，如果出现不等的字符，直接返回这两个字符的大小差值
        //2. 如果前k个字符相等(k为两个字符长度最小值)，返回值两个字符串长度差值
        System.out.println(str1.compareTo(str2));
        //忽略大小写进行比较
        System.out.println(str1.compareToIgnoreCase(str2));

        System.out.println(str1.equalsIgnoreCase(str2));
    }

    public static void main3(String[] args) {
        String str1 = new String("hello");
        String str2 = new String("hello");
        System.out.println(str1 == str2);
        //比较两个引用 所指向的对象当中的内容是否一致

        System.out.println(str1.equals(str2));
        //比较两个字符串中的内容是否相等，可以借助equals方法
    }
    public static void main2(String[] args) {
        String str1 = "hello";
        System.out.println(str1.length());
        int[] array = {1,2,3,4};
        System.out.println(array.length);

        String str2 = "";
        System.out.println(str2.length());
        System.out.println(str2.isEmpty());//表示所指向的对象为空
        String str3 = null;//表示它不指向任何对象
        System.out.println("gaobo".length()); //也可以是常量

    }

    public static void main1(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");
        System.out.println(str1);
        System.out.println(str2);
        //字符数组
        char[] values = {'a','b','c','d'};
        String str3 = new String(values);
        System.out.println(str3);
    }
}
